<?php

namespace app\system\model;

use app\system\model\Admin;
use app\system\model\business\Quotation;
use app\system\model\User;
use think\Model;


class Customer extends Model {
    /**
     * @var string 自动写入时间戳
     */
    protected $autoWriteTimestamp = true;

    public $append = [];

    public function getStatusAttr($value){
        return $value != '' && $value != null ? explode(',', $value) : [];
    }

    public function user(){
        return $this->hasOne(User::class, 'id', 'user_id');
    }

    public function admin(){
        return $this->hasOne(Admin::class, 'id', 'admin_id');
    }

    public function quotation(){
        return $this->hasMany(Quotation::class, 'business_id', 'id');
    }

    public function getImagesAttr($value){
        return empty($value) ? [] : explode(',', $value);
    }

//    public function getFilesAttr($value){
//        return empty($value) ? [] : json_decode($value, true);
//    }

    public function getCreateDateTextAttr($value, $data){
        return date('Y-m-d', $data['create_time']);
    }

    public function getCreateTimeTextAttr($value, $data){
        return date('H:i:s', $data['create_time']);
    }


}